package com.example.leetcode.leetcode;


import java.util.*;

/**
 * @author zhuhaitao
 * @email zhuhaitao@imoran.net
 * @date 2020/7/22 9:04 上午
 */
public class Test1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 票选情况
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> filter = new HashSet<>();
        // 得分情况
        Map<Integer, Integer> scoreMap = new HashMap<>();
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        for (int i = 0; i < m; i++) {
            int userId = scanner.nextInt();
            int scoreUserId = scanner.nextInt();
            // 已经票选过
            if (map.containsKey(userId)) {
                if (filter.contains(userId)) {
                    Integer scoreId = map.get(scoreUserId);
                    Integer score = scoreMap.get(scoreId);
                    scoreMap.put(scoreId, score - 1);
                } else {
                    filter.add(userId);
                }
                continue;
            }
            map.put(userId, scoreUserId);
            if (scoreMap.containsKey(scoreUserId)) {
                Integer score = scoreMap.get(scoreUserId);
                scoreMap.put(scoreUserId, score + 1);
            } else {
                scoreMap.put(scoreUserId, 1);
            }
        }
        int maxId = 0;
        int maxScore = 0;
        for (Map.Entry<Integer, Integer> entry : scoreMap.entrySet()) {
            Integer key = entry.getKey();
            Integer value = entry.getValue();
            if (value > maxScore) {
                maxId = key;
                maxScore = value;
            }
        }
        if (maxScore < n / 2) {
            System.out.println(-1);
        } else {
            System.out.println(maxId);
        }

    }
}
